﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using DTO;
using DAL;

namespace BLL
{
    public class Authentication
    {
        GetData data = new GetData();
        public bool IsUser(string Account, string Pass, ref string message)
        {
            if (data.FindUser(Account, CryptorEngine.Encrypt(Pass, true), ref message) != null)
            {
                return true;
            }
            else
            {
                return false;
            }

        }

        public List<PermitDetailEntity> LoadUserPermit(int userid)
        {
            return data.LoadUserPermit(userid);
        }

        public bool IsUserExisted(UserEntity user)
        {
            if (data.IsUserExisted(user))
            {
                return true;    //da ton tai
            }
            else
            {
                return false;   // chua ton tai
            }
        }

        public void UpdateUserInfo(UserEntity user)
        { 
            UpdateData update = new UpdateData();
            update.UpdateUserInfo(user);
        }

        public void ChangePass(UserEntity user)
        {
            UpdateData up = new UpdateData();
            user.Password = CryptorEngine.Encrypt(user.Password, true);
            up.ChangePass(user);            
        }

    }
}
